package cn.virens.service.impl.sys;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import cn.virens.database.common.BaseServiceImpl;
import cn.virens.database.common.mapper.ExampleWrapper;
import cn.virens.database.mysql.mapper.sys.SysResourceMapper;
import cn.virens.database.mysql.model.sys.SysResource;
import cn.virens.exception.APIException;
import cn.virens.service.inter.sys.SysResourceService;

/**
 * 资源管理 - sys_resource
 *
 * @author Virens
 * @since  2018-08-25 15:40:43
 */
@Service
public class SysResourceServiceImpl extends BaseServiceImpl<SysResourceMapper, SysResource> implements SysResourceService {

	public SysResourceServiceImpl() {
		super(SysResource.class);
	}

	@Override
	public List<SysResource> selectRoot() {
		ExampleWrapper example = ExampleWrapper.of(clazz);
		example.and().andEqualTo("pid", 0);

		return mBaseMapper.selectByExample(example);
	}

	@Override
	public List<SysResource> selectAll(Map<String, Object> param) {
		ExampleWrapper example = ExampleWrapper.of(clazz);
		example.and((criteria) -> {
			criteria.andLike("name", criteriaLike(param, "name"));
			criteria.andEqualTo("id", criteriaEqual(param, "id"));
			criteria.andEqualTo("pid", criteriaEqual(param, "pid"));
		});

		return mBaseMapper.selectByExample(example);
	}

	@Override
	public SysResource insert(SysResource record) {
		throw new APIException("DISABLE_API", "Disable create the resource!");
	}

	@Override
	public int delete(Serializable... id) {
		throw new APIException("DISABLE_API", "Disable delete the resource!");
	}
}
